package com.banzhi.shop.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.banzhi.shop.R;
import com.banzhi.shop.adapter.HomeFrgAda;
import com.banzhi.shop.base.BaseActivity;

import com.banzhi.shop.fragment.OrderFrg;
import com.banzhi.shop.utils.TabLayoutUtil;
import com.banzhi.shop.utils.Translucent;

import java.util.ArrayList;
import java.util.List;

/**
 * 订单管理
 */
public class OrderManagementActivity extends BaseActivity implements View.OnClickListener {
    /**
     * 退出
     */
    private ImageView ivback;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private ImageView tvshousuo;
    private int type;
    private TextView tvtitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_management);
        Translucent.setTranslucent(this);
        setinits();
        setListeners();
        Intent intent = getIntent();
        type = intent.getIntExtra("type", 0);
        if (type == 1) {
            tvtitle.setText("今日订单");
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        tabLayout.post(new Runnable() {
            @Override
            public void run() {
                TabLayoutUtil.setIndicator(tabLayout, 5, 5);
            }
        });
    }

    private void setinits() {
        ivback = (ImageView) findViewById(R.id.iv_back);
        tvtitle = (TextView) findViewById(R.id.tv_title);
        tvshousuo = (ImageView) findViewById(R.id.iv_sousuo);
        tabLayout = (TabLayout) findViewById(R.id.tabLayout);
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        viewPager.setOffscreenPageLimit(4);//同时加载旁边的fragment的页面布局
        List<Fragment> fras = new ArrayList<>();
        OrderFrg frg1 = new OrderFrg().newInstance("-1");//全部订单
        OrderFrg frg2 = new OrderFrg().newInstance("0");//待付款
        OrderFrg frg3 = new OrderFrg().newInstance("1");//待发货
        OrderFrg frg4 = new OrderFrg().newInstance("2");//待收货
        OrderFrg frg5 = new OrderFrg().newInstance("3");//已完成
        fras.add(frg1);
        fras.add(frg2);
        fras.add(frg3);
        fras.add(frg4);
        fras.add(frg5);
        List<String> list = new ArrayList<>();
        list.add("全部");
        list.add("待付款");
        list.add("待发货");
        list.add("待收货");
        list.add("已完成");
        HomeFrgAda homeFrgAda = new HomeFrgAda(this.getSupportFragmentManager(), fras, list);
        viewPager.setAdapter(homeFrgAda);
        tabLayout.setupWithViewPager(viewPager);
    }

    private void setListeners() {
        ivback.setOnClickListener(this);
        tvshousuo.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.iv_sousuo:
                Intent intent = new Intent(this, FindOrderActivity.class);
                startActivity(intent);
                break;
        }
    }

    public int getType() {
        return type;
    }
}
